package com.heima.controller;

import com.heima.pojo.dto.NodeAddDTO;
import com.heima.pojo.dto.NodePageDTO;
import com.heima.pojo.dto.NodeUpdateDTO;
import com.heima.pojo.entity.Business;
import com.heima.pojo.vo.NodeBsbusinessTypeVO;
import com.heima.pojo.vo.VendingMachineDetailsVO;
import com.heima.result.PageResult;
import com.heima.service.NodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/vm-service")
public class NodeController {
    @Autowired
    NodeService nodeService;

    /**
     * 区域查询
     */
    @GetMapping("/node/search")
    public PageResult<NodeBsbusinessTypeVO> page(NodePageDTO dto) {
        PageResult<NodeBsbusinessTypeVO> page = nodeService.pageSelect(dto);
        return page;
    }

    /**
     * 查询商圈列表
     */
    @GetMapping("/businessType")
    public List<Business> list() {
        List<Business> businesses = nodeService.selectBusiness();
        return businesses;
    }

    /**
     * 新增点位
     */
    @PostMapping("/node")
    public boolean nodeAdd(@RequestBody NodeAddDTO dto) {
        boolean result = nodeService.add(dto);
        return result;
    }

    /**
     * 获取点位详情
     */
    @GetMapping("/node/vmList/{nodeId}")
    public List<VendingMachineDetailsVO> getNodeDetails(@PathVariable String nodeId) {
        List<VendingMachineDetailsVO> NodeDetails = nodeService.NodeDetails(nodeId);
        return NodeDetails;
    }

    /**
     * 修改点位
     */
    @PutMapping("/node/{nodeId}")
    public boolean update(@PathVariable("nodeId") String nodeId, @RequestBody NodeUpdateDTO dto) {
        boolean result = nodeService.update(nodeId, dto);
        return result;
    }

    /**
     * 根据id删除
     */
    @DeleteMapping("/node/{nodeId}")
    public boolean delete(@PathVariable String nodeId) {
        boolean result = nodeService.delete(nodeId);
        return result;
    }

}
